function binarySearch(arr, target) {
  if (!arr) {
    throw new Error()
  }
  let l = 0,
    r = arr.length - 1 //  l r的意义 在 [l,r]左闭右闭区间内寻找等于target的变量

  while (l <= r) {
    let mid = Math.round((l + r) / 2)
    let mindValue = arr[mid]
    if (target > mindValue) {
      l = mid + 1
    } else if (target < mindValue) {
      r = mid - 1
    } else {
      return mid
    }
  }
  return -1
}
console.log(console.log(binarySearch([1, 2, 3, 4, 5], 5)))
